package org.example;

import com.google.gson.stream.JsonToken;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.resps.Tuple;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class demoZSet {
    public static void test1(Jedis jedis){
        System.out.println(" zset");
        jedis.flushAll();
        jedis.zadd("key",10,"zhangsan");
        Map<String,Double> map=new HashMap<>();
        map.put("lisi",20.0 );
        map.put("wangwu",3.3);
        jedis.zadd("key",map);
        List<Tuple> key = jedis.zrangeWithScores("key", 0, -1);
        System.out.println(jedis.zrangeWithScores("key", 0, -1)+" "+key);
        System.out.println(key.get(0).getElement()+key.get(0).getScore());
        System.out.println(jedis.zcard("key"));
        System.out.println(jedis.zrem("key","lisi"));
        System.out.println(jedis.zrangeWithScores("key", 0, -1));
        System.out.println(jedis.zscore("key", "zhangsan"));
        System.out.println(jedis.zscore("key", "lisi"));
        System.out.println(jedis.zrank("key", "lisi"));
        System.out.println(jedis.zrank("key", "zhangsan"));
    }




    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis=jedisPool.getResource()){
//            test(jedis);
//            test1(jedis);
//            test3(jedis);
            test1(jedis);
        }

    }
}
